﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Delay;
using System.ComponentModel;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
using Microsoft.Phone.Shell;
using PhoneInfo.Converters;

namespace PhoneInfo.Page
{

    public partial class PhonePk : PhoneApplicationPage
    {
        private PhonePkDetail typeParameter_1 = null;
        private PhonePkDetail typeParameter_2 = null;
        private PhonePkDetail typeParameter = null;
        private PhonePkVote phoneVote1 = null;
        private PhonePkVote phoneVote2 = null;
        private string pid_1;
        private string pid_2;
        private string name1;
        private string Imageurl1;
        private string name2;
        private string Imageurl2;
        private string jia1;
        private string jia2;
        private string ppname1;
        private string ppname2;
        private string phonename1;
        private string phonename2;
        private string ppid1;
        private string ppid2;
        private bool parameters_isloaded_1 = false;
        private bool parameters_isloaded_2 = false;
        bool delIndex1 = false;
        bool delIndex2 = false;

        //行情
        private TypePrice TypePrice_1 = null;
        private TypePrice TypePrice_2 = null;
        //点评
        private TypeCommentView typeComment_1 = null;
        private TypeCommentView typeComment_2 = null;
        private ScoreDetail scDetail_1 = null;
        private ScoreDetail scDetail_2 = null;
        private int lastComment_1Page = -1;
        private int lastComment_2Page = -1;
        //图片
        private TypePicture typePicture = null;
        private TypePicture typePicture_2 = null;
        //宝典
        BibleView bibleViewMarket = null;
        BibleView bibleViewTest = null;
        BibleView bibleViewSkill = null;
        BibleView bibleViewBug = null;
        BibleView bibleViewBuyPhone = null;

        BibleView bibleViewMarket_2 = null;
        BibleView bibleViewTest_2 = null;
        BibleView bibleViewSkill_2 = null;
        BibleView bibleViewBug_2 = null;
        BibleView bibleViewBuyPhone_2 = null;
        private int currentBible = -1;
        int loadParametersNumbers = 0;
        private int imageIndex = -1;
        bool isnull = false;
        private int addVoteNumer = 0;//该值为1 则为机型1 值为2则为机型2 值为0则不属于任何机型不做操作
        bool isShowPK1 = false;
        bool isShowPK2 = false;
        public PhonePk()
        {
            InitializeComponent();
            sto1.Completed += (_, __) => { isShowPK1 = true; };
            sto2.Completed += (_, __) => { isShowPK2 = true; };
            sto1_hide.Completed += (_, __) => { isShowPK1 = false; };
            sto2_hide.Completed += (_, __) => { isShowPK2 = false; };
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IDictionary<string, string> parameters = this.NavigationContext.QueryString;

            if (parameters.ContainsKey("optional"))
            {
                Ex1(); 
                Ex2();
                SystemTray.IsVisible = false;
                return;
            }


            if (parameters.ContainsKey("isnull"))
                isnull = true;

            if (parameters.ContainsKey("pid1"))
                pid_1 = parameters["pid1"];
            if (parameters.ContainsKey("pid1"))
                pid_1 = parameters["pid1"];
            if (parameters.ContainsKey("pid2"))
                pid_2 = parameters["pid2"];

            if (parameters.ContainsKey("ppid1"))
                ppid1 = parameters["ppid1"];
            if (parameters.ContainsKey("ppid2"))
                ppid2 = parameters["ppid2"];

            if (parameters.ContainsKey("jia1"))
                jia1 = parameters["jia1"];
            if (parameters.ContainsKey("jia2"))
                jia2 = parameters["jia2"];

            if (parameters.ContainsKey("ppname1"))
                ppname1 = parameters["ppname1"];
            if (parameters.ContainsKey("ppname2"))
                ppname2 = parameters["ppname2"];

            if (parameters.ContainsKey("phonename1"))
                phonename1 = parameters["phonename1"];
            if (parameters.ContainsKey("phonename2"))
                phonename2 = parameters["phonename2"];

            if (parameters.ContainsKey("name1"))
            {
                name1 = parameters["name1"];
                string str = parameters["name1"];
                if (str.Length >= 21) str = str.Substring(0, 19) + "..";
                TextType1.Text = str;
            }
            if (parameters.ContainsKey("name2"))
            {
                string str = parameters["name2"];
                if (str.Length >= 21) str = str.Substring(0, 19) + "..";
                TextType2.Text = str;
            }
            if (parameters.ContainsKey("picurl1"))
            {
                Imageurl1 = parameters["picurl1"];
                if (!delIndex1)
                    typePhone1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(parameters["picurl1"]));
            }
            if (parameters.ContainsKey("picurl2"))
            {
                Imageurl2 = parameters["picurl2"];
                if (!delIndex2)
                    typePhone2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(parameters["picurl2"]));
            }
            if (typeParameter_1 == null)
            {
                typeParameter_1 = new PhonePkDetail();
                typeParameter_1.ClassNmae = "typeParameter_1";
                ProgBar.Visibility = Visibility.Visible;
                typeParameter_1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                typeParameter_1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeParameter_1.GetPhoneInfoUrl(pid_1)));
            }
            if (typeParameter_2 == null)
            {
                typeParameter_2 = new PhonePkDetail();
                ProgBar.Visibility = Visibility.Visible;
                typeParameter_2.ClassNmae = "typeParameter_2";
                typeParameter_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                typeParameter_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeParameter_2.GetPhoneInfoUrl(pid_2)));
            }
            if (phoneVote1 == null)
            {
                phoneVote1 = new PhonePkVote();
                phoneVote1.className = "phoneVote1";
                phoneVote1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                phoneVote1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(phoneVote1.GetPhoneInfoUrl(pid_1)));
            }
            if (phoneVote2 == null)
            {
                phoneVote2 = new PhonePkVote();
                phoneVote2.className = "phoneVote2";
                phoneVote2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                phoneVote2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(phoneVote2.GetPhoneInfoUrl(pid_2)));
            }

            if (isnull)
            {
                Ex2();
            }
        }
        void type_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender == null) return;
            if (sender is PhonePkDetail)
            {
                PhonePkDetail pk1 = sender as PhonePkDetail;
                if (e.PropertyName == "ImageVis")
                    ProgBar.Visibility = Visibility.Collapsed;
                if (e.PropertyName == "IsLoaded")
                {
                    if (pk1.IsLoaded == true)
                    {
                        //一个参数家在成功
                        if (pk1.ClassNmae == "typeParameter_1")
                            parameters_isloaded_1 = true;
                        if (pk1.ClassNmae == "typeParameter_2")
                            parameters_isloaded_2 = true;
                        if (parameters_isloaded_1 == true && parameters_isloaded_2 == true)
                            copy_1_to_2();
                    }
                }
            }
            else if (sender is PhonePkVote)
            {
                PhonePkVote pkVote = sender as PhonePkVote;
                if (e.PropertyName == "IsLoaded")
                {
                    if (pkVote.IsLoaded == true)
                    {
                        //一个参数家在成功
                        if (pkVote.className == "phoneVote1")
                        {
                            progBar11.Value = pkVote.quality;
                            TextprogBar11.Text = pkVote.quality.ToString() + "%";
                            progBar21.Value = pkVote.Breed;
                            TextprogBar21.Text = pkVote.Breed.ToString() + "%";
                            progBar31.Value = pkVote.price;
                            TextprogBar31.Text = pkVote.price.ToString() + "%";
                            progBar41.Value = pkVote.effect;
                            TextprogBar41.Text = pkVote.effect.ToString() + "%";
                            progBar51.Value = pkVote.fece;
                            TextprogBar51.Text = pkVote.fece.ToString() + "%";
                            progBar61.Value = pkVote.other;
                            TextprogBar61.Text = pkVote.other.ToString() + "%";

                        }
                        else if (pkVote.className == "phoneVote2" && !isnull)
                        {
                            progBar12.Value = pkVote.quality;
                            TextprogBar12.Text = pkVote.quality.ToString() + "%";
                            progBar22.Value = pkVote.Breed;
                            TextprogBar22.Text = pkVote.Breed.ToString() + "%";
                            progBar32.Value = pkVote.price;
                            TextprogBar32.Text = pkVote.price.ToString() + "%";
                            progBar42.Value = pkVote.effect;
                            TextprogBar42.Text = pkVote.effect.ToString() + "%";
                            progBar52.Value = pkVote.fece;
                            TextprogBar52.Text = pkVote.fece.ToString() + "%";
                            progBar62.Value = pkVote.other;
                            TextprogBar62.Text = pkVote.other.ToString() + "%";
                        }
                    }
                }
            }

            else if (sender is TypePrice)
            {
                TypePrice pkPrice = sender as TypePrice;
                if (e.PropertyName == "Result")
                {
                    ProgBar.Visibility = Visibility.Collapsed;
                    if (PricePivot.SelectedIndex == 0)
                    {
                        if (pkPrice.Result == 1 || pkPrice.Result == -1)
                        {
                            //没有相关的信息
                            priceTextPivot1.Text = "没有找到相关的报价";
                            priceTextPivot1.Visibility = Visibility.Visible;
                        }
                    }
                    else if (PricePivot.SelectedIndex == 1)
                    {
                        if (pkPrice.Result == 1 || pkPrice.Result == -1)
                        {
                            //没有相关的信息
                            priceTextPivot2.Text = "没有找到相关的报价";
                            priceTextPivot2.Visibility = Visibility.Visible;
                        }
                        else if (pkPrice.Result == -1)
                        {
                            priceTextPivot2.Text = "没有找到相关的报价";
                            priceTextPivot1.Visibility = Visibility.Collapsed;
                        }
                    }

                }
            }
            else if (sender is ScoreDetail)
            {
                ScoreDetail tp = sender as ScoreDetail;
                if (tp == null) return;
                if (e.PropertyName == "TotalScore")
                {
                    if (commentPivot.SelectedIndex == 0)
                    {
                        if (tp.TotalScore != 0)
                        {
                            sc1.Value = (float)tp.Sc1 * 100 / tp.TotalScore;                        //
                            sc2.Value = (float)tp.Sc2 * 100 / tp.TotalScore;                        //
                            sc3.Value = (float)tp.Sc3 * 100 / tp.TotalScore;                        //
                            sc4.Value = (float)tp.Sc4 * 100 / tp.TotalScore;                        //
                            sc5.Value = (float)tp.Sc5 * 100 / tp.TotalScore;
                            //
                            Textsc1.Text = tp.Sc1.ToString() + "人";
                            Textsc2.Text = tp.Sc2.ToString() + "人";
                            Textsc3.Text = tp.Sc3.ToString() + "人";
                            Textsc4.Text = tp.Sc4.ToString() + "人";
                            Textsc5.Text = tp.Sc5.ToString() + "人";

                            float avg = (float)(tp.Sc1 * 1.0 + tp.Sc2 * 2.0 + tp.Sc3 * 3.0 + tp.Sc4 * 4.0 + tp.Sc5 * 5.0) / tp.TotalScore;
                            scoreText.Text = avg.ToString("#.#");
                            ScoreStart.Marked = (int)avg;
                        }
                        else
                        {
                            scoreText.Text = "0分";
                            ScoreStart.Marked = 0;
                        }
                    }
                    else if (commentPivot.SelectedIndex == 1)
                    {
                        if (tp.TotalScore != 0)
                        {
                            sc1_2.Value = (float)tp.Sc1 * 100 / tp.TotalScore;                        //
                            sc2_2.Value = (float)tp.Sc2 * 100 / tp.TotalScore;                        //
                            sc3_2.Value = (float)tp.Sc3 * 100 / tp.TotalScore;                        //
                            sc4_2.Value = (float)tp.Sc4 * 100 / tp.TotalScore;                        //
                            sc5_2.Value = (float)tp.Sc5 * 100 / tp.TotalScore;
                            //
                            Textsc1_2.Text = tp.Sc1.ToString() + "人";
                            Textsc2_2.Text = tp.Sc2.ToString() + "人";
                            Textsc3_2.Text = tp.Sc3.ToString() + "人";
                            Textsc4_2.Text = tp.Sc4.ToString() + "人";
                            Textsc5_2.Text = tp.Sc5.ToString() + "人";

                            float avg = (float)(tp.Sc1 * 1.0 + tp.Sc2 * 2.0 + tp.Sc3 * 3.0 + tp.Sc4 * 4.0 + tp.Sc5 * 5.0) / tp.TotalScore;
                            scoreText_2.Text = avg.ToString("#.#");
                            ScoreStart_2.Marked = (int)avg;
                        }
                        else
                        {
                            scoreText_2.Text = "0分";
                            ScoreStart_2.Marked = 0;
                        }
                    }
                }
            }
            else if (sender is TypeCommentView)
            {
                TypeCommentView tc = new TypeCommentView();
                if (e.PropertyName == "Result")
                {
                    if (tc.Result == 1 || tc.Result == 1)
                    {
                        switch (commentPivot.SelectedIndex)
                        {
                            case 0:
                                break;
                            case 1:
                                break;
                        }
                        CommentResult1.Visibility = Visibility.Visible;
                    }
                    ProgBar.Visibility = Visibility.Collapsed;
                }
            }
            else if (sender is BibleView)
            {
                BibleView bv = sender as BibleView;
                if (bv == null) return;
                if (e.PropertyName == "Result")
                {
                    //进行处理
                    ProgBar.Visibility = Visibility.Collapsed;//
                    if (bv.Result == 1 || bv.Result == -1)
                    {
                        if (BiblePivot.SelectedIndex == 0)
                        {
                            switch (BibleTab.SelectedIndex)
                            {
                                case 0:
                                    //行情
                                    TextBibleMarket.Visibility = Visibility.Visible;
                                    break;
                                case 1:
                                    //测评
                                    TextBibleTest.Visibility = Visibility.Visible;
                                    break;
                                case 2:
                                    //技能
                                    TextBibleSkill.Visibility = Visibility.Visible;
                                    break;
                                case 3:
                                    //bug
                                    TextBibleBug.Visibility = Visibility.Visible;
                                    break;
                                case 4:
                                    TextBibleBuy.Visibility = Visibility.Visible;
                                    break;
                            }
                        }

                        else if (BiblePivot.SelectedIndex == 1)
                        {
                            switch (BibleTab_2.SelectedIndex)
                            {
                                case 0:
                                    //行情
                                    TextBibleMarket_2.Visibility = Visibility.Visible;
                                    break;
                                case 1:
                                    //测评
                                    TextBibleTest_2.Visibility = Visibility.Visible;
                                    break;
                                case 2:
                                    //技能
                                    TextBibleSkill_2.Visibility = Visibility.Visible;
                                    break;
                                case 3:
                                    //bug
                                    TextBibleBug_2.Visibility = Visibility.Visible;
                                    break;
                                case 4:
                                    TextBibleBuy_2.Visibility = Visibility.Visible;
                                    break;
                            }
                        }
                    }
                }
            }
            else if (sender is ReplyResult)
            {
                ReplyResult se = (ReplyResult)sender;
                if (e.PropertyName == "Result")
                {
                    if (se.Result == 1 || se.Result == 2)
                    {//成功
                        ProgBarPop.Visibility = Visibility.Collapsed;
                        Advant.IsEnabled = true;
                        Defect.IsEnabled = true;
                        PopFull.IsOpen = false;
                        Conmmit.IsEnabled = true;

                        if (commentPivot.SelectedIndex == 0)
                        {
                            typeComment_1 = new TypeCommentView();
                            ProgBar.Visibility = Visibility.Visible;
                            typeComment_1.Result = 0;
                            typeComment_1.CurrentPage = 1;
                            typeComment_1.AllowAdd = false;
                            typeComment_1.PageSize = 10;
                            typeComment_1.TotalPage = 0;
                            typeComment_1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeComment_1.GetPhoneInfoUrl(pid_1, typeComment_1.CurrentPage)));
                            typeComment_1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            commetPivotItem_1.DataContext = typeComment_1;
                        }
                        else if (commentPivot.SelectedIndex == 1)
                        {
                            typeComment_2 = new TypeCommentView();
                            ProgBar.Visibility = Visibility.Visible;
                            typeComment_2.Result = 0;
                            typeComment_2.CurrentPage = 1;
                            typeComment_2.AllowAdd = false;
                            typeComment_2.PageSize = 10;
                            typeComment_2.TotalPage = 0;
                            typeComment_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeComment_2.GetPhoneInfoUrl(pid_2, typeComment_2.CurrentPage)));
                            typeComment_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            commetPivotItem_2.DataContext = typeComment_2;
                        }

                        new ToastPrompt() { Message = "点评成功！" }.Show();
                    }
                    else
                    {//失败
                        SystemTray.IsVisible = true;
                        ProgBarPop.Visibility = Visibility.Collapsed;
                        Advant.IsEnabled = true;
                        Defect.IsEnabled = true;
                        Conmmit.IsEnabled = true;
                        MessageBox.Show("提交评论失败，点确定退出改页面，点取消继续评论", "提示", MessageBoxButton.OK | MessageBoxButton.OKCancel);
                    }
                }
            }
            else if (sender is TypePicture)
            {
                TypePicture tp = sender as TypePicture;
                if (tp == null) return;
                if (e.PropertyName == "Result")
                {
                    //进行处理
                    ProgBar.Visibility = Visibility.Visible;
                    ProgBar.Visibility = Visibility.Collapsed;//
                    switch (picturePivot.SelectedIndex)
                    {
                        case 0:
                            switch (tp.Result)
                            {
                                case -1:
                                    pictureTextPivot1.Text = "网络错误，请稍后重试！";
                                    pictureTextPivot1.Visibility = Visibility.Visible;

                                    break;
                                case 1:
                                    pictureTextPivot1.Text = "没有您要查找的信息";
                                    pictureTextPivot1.Visibility = Visibility.Visible;
                                    break;
                                case 2:
                                    pictureTextPivot1.Visibility = Visibility.Collapsed;
                                    break;
                            }
                            break;
                        case 1:
                            switch (tp.Result)
                            {
                                case -1:
                                    pictureTextPivot2.Text = "网络错误，请稍后重试！";
                                    pictureTextPivot2.Visibility = Visibility.Visible;
                                    break;
                                case 1:
                                    pictureTextPivot2.Text = "没有您要查找的信息";
                                    pictureTextPivot2.Visibility = Visibility.Visible;
                                    break;
                                case 2:
                                    pictureTextPivot2.Visibility = Visibility.Collapsed;
                                    break;
                            }
                            break;
                    }
                }
            }
        }
        void copy_1_to_2()
        {
            if (typeParameter_1 == null || typeParameter_2 == null) return;
            if (typeParameter == null)
            {
                typeParameter = new PhonePkDetail();
                typeParameter.ClassNmae = "typeParameter_1";
                listType1.DataContext = typeParameter;
            }
            for (int i = 0; i < typeParameter_1.TypeParameterItems.Count; i++)
            {
                for (int j = i; j < typeParameter_2.TypeParameterItems.Count; j++)
                {
                    if (typeParameter_1.TypeParameterItems[i].Title == typeParameter_2.TypeParameterItems[j].Title)
                    {
                        typeParameter_1.TypeParameterItems[i].Content_2 = typeParameter_2.TypeParameterItems[j].Content;
                        break;
                    }
                }
            }
            for (int i = 0; i < typeParameter_1.TypeParameterItems.Count; i++)
                typeParameter.TypeParameterItems.Add(typeParameter_1.TypeParameterItems[i]);
            loadParametersNumbers = typeParameter.TypeParameterItems.Count;
            ProgBar.Visibility = Visibility.Collapsed;
        }
        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null) return;
            Pivot pv = sender as Pivot;
            if (pv != null)
            {
                switch (pv.SelectedIndex)
                {
                    case 0:
                        textType1.Visibility = Visibility.Visible;
                        textWatch1.Visibility = Visibility.Visible;
                        textType2.Visibility = Visibility.Collapsed;
                        textWatch2.Visibility = Visibility.Collapsed;
                        if (delIndex1) break;
                        break;
                    case 1:
                        textType2.Visibility = Visibility.Visible;
                        textWatch2.Visibility = Visibility.Visible;
                        textType1.Visibility = Visibility.Collapsed;
                        textWatch1.Visibility = Visibility.Collapsed;
                        if (delIndex2) break;
                        //增加下载第二页的内容
                        if ((sender as Pivot).Items.Count == 2 )
                        {
                            TypePrice_2 = new TypePrice();
                            ProgBar.Visibility = Visibility.Visible;
                            TypePrice_2.Result = 0;
                            TypePrice_2.CurrentPage = 1;
                            TypePrice_2.AllowAdd = false;
                            TypePrice_2.PageSize = 10;
                            TypePrice_2.TotalPage = 0;
                            TypePrice_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(TypePrice_1.GetPhoneInfoUrl(pid_2, TypePrice_2.CurrentPage)));
                            TypePrice_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            TypePriceList2.DataContext = TypePrice_2;
                        }
                        break;
                }
            }
        }
        private void PivotItem_Loaded(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            if (name1 != null) textTypeName1.Text = name1;
            if (name2 != null) textTypeName2.Text = name2;
            if (Imageurl1 != null) ImageTypeName1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl1));
            if (Imageurl2 != null) ImageTypeName2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl2));
        }
        public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement
        {
            List<T> visualCollection = new List<T>();
            GetVisualChildCollection(parent as DependencyObject, visualCollection);
            return visualCollection;
        }
        private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : UIElement
        {
            int count = VisualTreeHelper.GetChildrenCount(parent);
            for (int i = 0; i < count; i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(parent, i);
                if (child is T)
                    visualCollection.Add(child as T);
                else if (child != null)
                    GetVisualChildCollection(child, visualCollection);
            }
        }
        private void FirstListBox_Loaded(object sender, RoutedEventArgs e)
        {
            List<ScrollBar> scrollBarList = GetVisualChildCollection<ScrollBar>(sender);
            foreach (ScrollBar scrollBar in scrollBarList)
            {
                if (scrollBar.Orientation != System.Windows.Controls.Orientation.Horizontal)
                    scrollBar.ValueChanged += new RoutedPropertyChangedEventHandler<double>(verticalScrollBar_ValueChanged);
            }
        }
        private void verticalScrollBar_ValueChanged(object sender, RoutedEventArgs e)
        {
            ScrollBar scrollBar = (ScrollBar)sender;
            object valueObj = scrollBar.GetValue(ScrollBar.ValueProperty);
            object maxObj = scrollBar.GetValue(ScrollBar.MaximumProperty);
            Debug.WriteLine("ValueProperty si {0}", valueObj);
            Debug.WriteLine("MaximumProperty si {0}", maxObj);
            if (valueObj != null && maxObj != null)
            {
                double value = (double)valueObj;
                double max = (double)maxObj - 1.5;
                if (value >= max)
                {
                    switch (tabswitch.SelectedIndex)
                    {
                        case 0:
                            addMoreParameter();
                            break;
                        case 2:
                            addMoreComment();
                            break;
                        case 4:
                            addMoreBible();
                            break;
                    }
                }
            }
        }
        private void addMoreParameter()
        {
            if (loadParametersNumbers < typeParameter_1.TypeParameterItems.Count)
            {
                for (int i = loadParametersNumbers; i < loadParametersNumbers + 15 && i < typeParameter_1.TypeParameterItems.Count; i++)
                    typeParameter.TypeParameterItems.Add(typeParameter_1.TypeParameterItems[i]);
                loadParametersNumbers = typeParameter.TypeParameterItems.Count;
            }
        }
        private void addMoreComment()
        {
            switch (commentPivot.SelectedIndex)
            {
                case 0:
                    {
                        TypeCommentView currentItem = commetPivotItem_1.DataContext as TypeCommentView;
                        if (currentItem == null) break;
                        if (lastComment_1Page == currentItem.CurrentPage) return;
                        lastComment_1Page = currentItem.CurrentPage;
                        //已经修改模型事件的回调函数中更改防止 同一页面加载2次
                        if (currentItem.CurrentPage * currentItem.PageSize <= currentItem.TotalPage)
                        {
                            ProgBar.Visibility = Visibility.Visible;
                            currentItem.Result = 0;
                            currentItem.AllowAdd = true;
                            currentItem.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(currentItem.GetPhoneInfoUrl(pid_1, currentItem.CurrentPage + 1)));
                        }
                    }
                    break;
                case 1:
                    {
                        TypeCommentView currentItem = commetPivotItem_2.DataContext as TypeCommentView;
                        if (currentItem == null) break;
                        if (lastComment_2Page == currentItem.CurrentPage) return;
                        lastComment_2Page = currentItem.CurrentPage;
                        //已经修改模型事件的回调函数中更改防止 同一页面加载2次
                        if (currentItem.CurrentPage * currentItem.PageSize <= currentItem.TotalPage)
                        {
                            ProgBar.Visibility = Visibility.Visible;
                            currentItem.Result = 0;
                            currentItem.AllowAdd = true;
                            currentItem.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(currentItem.GetPhoneInfoUrl(pid_2, currentItem.CurrentPage + 1)));
                        }
                    }
                    break;
            }
        }
        private void addMoreBible()
        {
            switch (BiblePivot.SelectedIndex)
            {
                case 0:
                    switch (BibleTab.SelectedIndex)
                    {
                        case 0:
                            {
                                if (bibleViewMarket.CurrentPage * bibleViewMarket.PageSize <= bibleViewMarket.TotalPage)
                                {
                                    if (currentBible == bibleViewMarket.CurrentPage) return;
                                    currentBible = bibleViewMarket.CurrentPage;
                                    bibleViewMarket.Result = 0;
                                    bibleViewMarket.AllowAdd = true;
                                    bibleViewMarket.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewMarket.GetPhoneInfoUrl(bibleViewMarket.CurrentPage + 1, 0, pid_1)));
                                }
                            }
                            break;
                        case 1:
                            {

                                if (bibleViewTest.CurrentPage * bibleViewTest.PageSize <= bibleViewTest.TotalPage)
                                {
                                    if (currentBible == bibleViewTest.CurrentPage) return;
                                    currentBible = bibleViewTest.CurrentPage;
                                    bibleViewTest.Result = 0;
                                    bibleViewTest.AllowAdd = false;
                                    bibleViewTest.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewTest.GetPhoneInfoUrl(bibleViewTest.CurrentPage + 1, 0, pid_1)));
                                }
                            }
                            break;
                        case 3:
                            {
                                if (bibleViewBug.CurrentPage * bibleViewBug.PageSize <= bibleViewBug.TotalPage)
                                {
                                    if (currentBible == bibleViewBug.CurrentPage) return;
                                    currentBible = bibleViewBug.CurrentPage;
                                    bibleViewBug.Result = 0;
                                    bibleViewBug.AllowAdd = false;
                                    bibleViewBug.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewBug.GetPhoneInfoUrl(bibleViewBug.CurrentPage + 1, 0, pid_1)));
                                }
                            }
                            break;
                        case 2:
                            {
                                if (bibleViewSkill.CurrentPage * bibleViewSkill.PageSize <= bibleViewSkill.TotalPage)
                                {
                                    if (currentBible == bibleViewSkill.CurrentPage) return;
                                    currentBible = bibleViewSkill.CurrentPage;
                                    bibleViewSkill.Result = 0;
                                    bibleViewSkill.AllowAdd = false;
                                    bibleViewSkill.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewSkill.GetPhoneInfoUrl(bibleViewSkill.CurrentPage + 1, 0, pid_1)));
                                }
                            }
                            break;
                        case 4:
                            {
                                if (bibleViewBuyPhone.CurrentPage * bibleViewBuyPhone.PageSize <= bibleViewBuyPhone.TotalPage)
                                {
                                    if (currentBible == bibleViewBuyPhone.CurrentPage) return;
                                    currentBible = bibleViewBuyPhone.CurrentPage;
                                    bibleViewBuyPhone.Result = 0;
                                    bibleViewBuyPhone.AllowAdd = false;
                                    bibleViewBuyPhone.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewBuyPhone.GetPhoneInfoUrl(bibleViewBuyPhone.CurrentPage + 1, 0, pid_1)));
                                }
                            }
                            break;
                    }

                    break;
                case 1:
                    switch (BibleTab.SelectedIndex)
                    {
                        case 0:
                            {
                                if (bibleViewMarket_2.CurrentPage * bibleViewMarket_2.PageSize <= bibleViewMarket_2.TotalPage)
                                {
                                    if (currentBible == bibleViewMarket_2.CurrentPage) return;
                                    currentBible = bibleViewMarket_2.CurrentPage;
                                    bibleViewMarket_2.Result = 0;
                                    bibleViewMarket_2.AllowAdd = false;
                                    bibleViewMarket_2.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewMarket_2.GetPhoneInfoUrl(bibleViewMarket_2.CurrentPage + 1, 0, pid_2)));
                                }
                            }
                            break;
                        case 1:
                            {
                                if (bibleViewTest_2.CurrentPage * bibleViewTest_2.PageSize <= bibleViewTest_2.TotalPage)
                                {
                                    if (currentBible == bibleViewTest_2.CurrentPage) return;
                                    currentBible = bibleViewTest_2.CurrentPage;
                                    bibleViewTest_2.Result = 0;
                                    bibleViewTest_2.AllowAdd = false;
                                    bibleViewTest_2.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewTest_2.GetPhoneInfoUrl(bibleViewTest_2.CurrentPage + 1, 0, pid_2)));
                                }
                            }
                            break;
                        case 3:
                            {
                                if (bibleViewBug_2.CurrentPage * bibleViewBug_2.PageSize <= bibleViewBug_2.TotalPage)
                                {
                                    if (currentBible == bibleViewBug_2.CurrentPage) return;
                                    currentBible = bibleViewBug_2.CurrentPage;
                                    bibleViewBug_2.Result = 0;
                                    bibleViewBug_2.AllowAdd = false;
                                    bibleViewBug_2.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewBug_2.GetPhoneInfoUrl(bibleViewBug_2.CurrentPage + 1, 0, pid_2)));
                                }
                            }
                            break;
                        case 2:
                            {
                                if (bibleViewSkill_2.CurrentPage * bibleViewSkill_2.PageSize <= bibleViewSkill_2.TotalPage)
                                {
                                    if (currentBible == bibleViewSkill_2.CurrentPage) return;
                                    currentBible = bibleViewSkill_2.CurrentPage;
                                    bibleViewSkill_2.Result = 0;
                                    bibleViewSkill_2.AllowAdd = false;
                                    bibleViewSkill_2.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewSkill_2.GetPhoneInfoUrl(bibleViewSkill_2.CurrentPage + 1, 0, pid_2)));
                                }
                            }
                            break;
                        case 4:
                            {
                                if (bibleViewBuyPhone_2.CurrentPage * bibleViewBuyPhone_2.PageSize <= bibleViewBuyPhone_2.TotalPage)
                                {
                                    if (currentBible == bibleViewBuyPhone_2.CurrentPage) return;
                                    currentBible = bibleViewBuyPhone_2.CurrentPage;
                                    bibleViewBuyPhone_2.Result = 0;
                                    bibleViewBuyPhone_2.AllowAdd = false;
                                    bibleViewBuyPhone_2.SetValue(LowProfileXmlLoader.UriSourceProperty,
                                                    new Uri(bibleViewBuyPhone_2.GetPhoneInfoUrl(bibleViewBuyPhone_2.CurrentPage + 1, 0, pid_2)));
                                }
                            }
                            break;
                    }
                    break;
            }

        }
        private void tabswitch_Selected(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            TabSwitch ts = sender as TabSwitch;
            if (ts == null) return;
            switch (ts.SelectedIndex)
            {
                case 0:
                    parameter.Visibility = Visibility.Visible;
                    price.Visibility = Visibility.Collapsed;
                    commet.Visibility = Visibility.Collapsed;
                    picture.Visibility = Visibility.Collapsed;
                    Bible.Visibility = Visibility.Collapsed;
                    //行情
                    break;
                case 1:
                    //这里添加数据
                    parameter.Visibility = Visibility.Collapsed;
                    price.Visibility = Visibility.Visible;
                    commet.Visibility = Visibility.Collapsed;
                    picture.Visibility = Visibility.Collapsed;
                    Bible.Visibility = Visibility.Collapsed;
                    if (TypePrice_1 == null )
                    {
                        TypePrice_1 = new TypePrice();
                        ProgBar.Visibility = Visibility.Visible;
                        TypePrice_1.Result = 0;
                        TypePrice_1.CurrentPage = 1;
                        TypePrice_1.AllowAdd = false;
                        TypePrice_1.PageSize = 10;
                        TypePrice_1.TotalPage = 0;
                        TypePrice_1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(TypePrice_1.GetPhoneInfoUrl(pid_1, TypePrice_1.CurrentPage)));
                        TypePrice_1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        if (delIndex1) break;
                        TypePriceList1.DataContext = TypePrice_1;
                    }
                    break;
                case 2:
                    parameter.Visibility = Visibility.Collapsed;
                    price.Visibility = Visibility.Collapsed;
                    commet.Visibility = Visibility.Visible;
                    picture.Visibility = Visibility.Collapsed;
                    Bible.Visibility = Visibility.Collapsed;
                    if (delIndex1) break;
                    if (scDetail_1 == null)
                    {
                        scDetail_1 = new ScoreDetail();
                        scDetail_1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        scDetail_1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(scDetail_1.GetPhoneInfoUrl(pid_1)));
                    }
                    if (typeComment_1 == null)
                    {
                        typeComment_1 = new TypeCommentView();
                        ProgBar.Visibility = Visibility.Visible;
                        typeComment_1.Result = 0;
                        typeComment_1.CurrentPage = 1;
                        typeComment_1.AllowAdd = false;
                        typeComment_1.PageSize = 10;
                        typeComment_1.TotalPage = 0;
                        typeComment_1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeComment_1.GetPhoneInfoUrl(pid_1, typeComment_1.CurrentPage)));
                        typeComment_1.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        commetPivotItem_1.DataContext = typeComment_1;
                    }

                    break;
                case 3:
                    parameter.Visibility = Visibility.Collapsed;
                    price.Visibility = Visibility.Collapsed;
                    commet.Visibility = Visibility.Collapsed;
                    picture.Visibility = Visibility.Visible;
                    Bible.Visibility = Visibility.Collapsed;
                    if (delIndex1) break;
                    if (typePicture == null)
                    {
                        typePicture = new TypePicture();
                        ProgBar.Visibility = Visibility.Visible;
                        typePicture.ImageVis = false;
                        typePicture.CurrentPage = 1;
                        typePicture.AllowAdd = false;
                        typePicture.PageSize = 20;
                        typePicture.TotalPage = 0;
                        typePicture.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typePicture.GetPhoneInfoUrl(pid_1, typePicture.CurrentPage)));
                        typePicture.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        PictruePivotItem1.DataContext = typePicture;
                    }


                    break;
                case 4:
                    parameter.Visibility = Visibility.Collapsed;
                    price.Visibility = Visibility.Collapsed;
                    commet.Visibility = Visibility.Collapsed;
                    picture.Visibility = Visibility.Collapsed;
                    Bible.Visibility = Visibility.Visible;
                    if (delIndex1) break;
                    //图片更换
                    if (bibleViewMarket == null)
                    {
                        bibleViewMarket = new BibleView();
                        ProgBar.Visibility = Visibility.Visible;
                        bibleViewMarket.Result = 0;
                        bibleViewMarket.CurrentPage = 1;
                        bibleViewMarket.AllowAdd = false;
                        bibleViewMarket.PageSize = 20;
                        bibleViewMarket.TotalPage = 0;
                        bibleViewMarket.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewMarket.GetPhoneInfoUrl(bibleViewMarket.CurrentPage, 0, pid_1)));
                        bibleViewMarket.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        BibleMarket.DataContext = bibleViewMarket;
                    }
                    break;
            }
        }
        private void Comment_Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null) return;
            Pivot pv = sender as Pivot;
            if (pv != null)
            {
                switch (pv.SelectedIndex)
                {
                    case 0:
                        textComment2.Visibility = Visibility.Collapsed;
                        textCommentWatch2.Visibility = Visibility.Collapsed;
                        textComment1.Visibility = Visibility.Visible;
                        textCommentWatch1.Visibility = Visibility.Visible;
                        if (delIndex1) break;
                        break;
                    case 1:
                        textComment2.Visibility = Visibility.Visible;
                        textCommentWatch2.Visibility = Visibility.Visible;
                        textComment1.Visibility = Visibility.Collapsed;
                        textCommentWatch1.Visibility = Visibility.Collapsed;
                        if (delIndex2) break;
                        if (scDetail_2 == null)
                        {
                            scDetail_2 = new ScoreDetail();
                            scDetail_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            scDetail_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(scDetail_2.GetPhoneInfoUrl(pid_2)));
                        }
                        if (typeComment_2 == null)
                        {
                            typeComment_2 = new TypeCommentView();
                            ProgBar.Visibility = Visibility.Visible;
                            typeComment_2.Result = 0;
                            typeComment_2.CurrentPage = 1;
                            typeComment_2.AllowAdd = false;
                            typeComment_2.PageSize = 10;
                            typeComment_2.TotalPage = 0;
                            typeComment_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typeComment_2.GetPhoneInfoUrl(pid_2, typeComment_2.CurrentPage)));
                            typeComment_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            commetPivotItem_2.DataContext = typeComment_2;
                        }
                        break;
                }
            }

        }
        private void Comment_Pivot_Loaded(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            if (name1 != null) textCommentName1.Text = name1;
            if (name2 != null) textCommentName2.Text = name2;
            if (Imageurl1 != null) ImageCommentName1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl1));
            if (Imageurl2 != null) ImageCommentName2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl2));
        }
        private void Into_Full_Click(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            SystemTray.IsVisible = false;
            PopFull.Visibility = Visibility.Visible;
            PopFull.IsOpen = true;
        }
        private void Pictrue_Pivot_Loaded(object sender, RoutedEventArgs e)
        {
            if (name1 != null) textPictureName1.Text = name1;
            if (Imageurl1 != null) ImagePictureName1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl1));
            if (name2 != null) textPictureName2.Text = name2;
            if (Imageurl2 != null) ImagePictureName2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl2));
        }
        private void Bible_Pivot_Loaded(object sender, RoutedEventArgs e)
        {
            if (name1 != null) textBibleName1.Text = name1;
            if (Imageurl1 != null) ImageBibleName1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl1));
            if (name2 != null) textBibleName2.Text = name2;
            if (Imageurl2 != null) ImageBibleName2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(Imageurl2));
        }
        private void Bible_Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null) return;
            Pivot pv = sender as Pivot;
            if (pv == null) return;
            currentBible = -1;
            switch (pv.SelectedIndex)
            {
                case 0:
                    textBible1.Visibility = Visibility.Visible;
                    textBibleWatch1.Visibility = Visibility.Visible;
                    textBible2.Visibility = Visibility.Collapsed;
                    textBibleWatch2.Visibility = Visibility.Collapsed;
                    if (delIndex1) break;
                    switch (BibleTab.SelectedIndex)
                    {
                        case 0:
                            BibleTab.SelectedIndex = BibleTab.SelectedIndex;
                            if (bibleViewMarket == null)
                            {
                                bibleViewMarket = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewMarket.Result = 0;
                                bibleViewMarket.CurrentPage = 1;
                                bibleViewMarket.AllowAdd = false;
                                bibleViewMarket.PageSize = 20;
                                bibleViewMarket.TotalPage = 0;
                                bibleViewMarket.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewMarket.GetPhoneInfoUrl(bibleViewMarket.CurrentPage, 0, pid_1)));
                                bibleViewMarket.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleMarket.DataContext = bibleViewMarket;
                            }
                            break;
                        case 1:
                            BibleTab.SelectedIndex = BibleTab_2.SelectedIndex;
                            if (bibleViewTest == null)
                            {
                                bibleViewTest = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewTest.Result = 0;
                                bibleViewTest.CurrentPage = 1;
                                bibleViewTest.AllowAdd = false;
                                bibleViewTest.PageSize = 20;
                                bibleViewTest.TotalPage = 0;
                                bibleViewTest.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewTest.GetPhoneInfoUrl(bibleViewTest.CurrentPage, 5, pid_1)));
                                bibleViewTest.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleTest.DataContext = bibleViewTest;
                            }

                            break;
                        case 2:
                            BibleTab.SelectedIndex = BibleTab_2.SelectedIndex;
                            if (bibleViewSkill == null)
                            {
                                bibleViewSkill = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewSkill.Result = 0;
                                bibleViewSkill.CurrentPage = 1;
                                bibleViewSkill.AllowAdd = false;
                                bibleViewSkill.PageSize = 20;
                                bibleViewSkill.TotalPage = 0;
                                bibleViewSkill.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewSkill.GetPhoneInfoUrl(bibleViewSkill.CurrentPage, 1, pid_1)));
                                bibleViewSkill.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleSkill.DataContext = bibleViewSkill;
                            }
                            break;
                        case 3:
                            BibleTab.SelectedIndex = BibleTab_2.SelectedIndex;
                            if (bibleViewBug == null)
                            {
                                bibleViewBug = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewBug.Result = 0;
                                bibleViewBug.CurrentPage = 1;
                                bibleViewBug.AllowAdd = false;
                                bibleViewBug.PageSize = 20;
                                bibleViewBug.TotalPage = 0;
                                bibleViewBug.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBug.GetPhoneInfoUrl(bibleViewBug.CurrentPage, 3, pid_1)));
                                bibleViewBug.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleBug.DataContext = bibleViewBug;
                            }
                            break;
                        case 4:
                            BibleTab.SelectedIndex = BibleTab_2.SelectedIndex;
                            if (bibleViewBuyPhone == null)
                            {
                                bibleViewBuyPhone = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewBuyPhone.Result = 0;
                                bibleViewBuyPhone.CurrentPage = 1;
                                bibleViewBuyPhone.AllowAdd = false;
                                bibleViewBuyPhone.PageSize = 20;
                                bibleViewBuyPhone.TotalPage = 0;
                                bibleViewBuyPhone.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBuyPhone.GetPhoneInfoUrl(bibleViewBuyPhone.CurrentPage, 4, pid_1)));
                                bibleViewBuyPhone.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleBuyphone.DataContext = bibleViewBuyPhone;
                            }
                            break;
                    }
                    break;
                case 1:
                    if (isnull || delIndex2) break;
                    textBible2.Visibility = Visibility.Visible;
                    textBibleWatch2.Visibility = Visibility.Visible;
                    textBible1.Visibility = Visibility.Collapsed;
                    textBibleWatch1.Visibility = Visibility.Collapsed;
                    switch (BibleTab.SelectedIndex)
                    {
                        case 0:
                            BibleTab_2.SelectedIndex = BibleTab.SelectedIndex;
                            if (bibleViewMarket_2 == null)
                            {
                                bibleViewMarket_2 = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewMarket_2.Result = 0;
                                bibleViewMarket_2.CurrentPage = 1;
                                bibleViewMarket_2.AllowAdd = false;
                                bibleViewMarket_2.PageSize = 20;
                                bibleViewMarket_2.TotalPage = 0;
                                bibleViewMarket_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewMarket_2.GetPhoneInfoUrl(bibleViewMarket_2.CurrentPage, 0, pid_2)));
                                bibleViewMarket_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleMarket_2.DataContext = bibleViewMarket_2;
                            }
                            break;
                        case 1:
                            BibleTab_2.SelectedIndex = BibleTab.SelectedIndex;
                            if (bibleViewTest_2 == null)
                            {
                                bibleViewTest_2 = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewTest_2.Result = 0;
                                bibleViewTest_2.CurrentPage = 1;
                                bibleViewTest_2.AllowAdd = false;
                                bibleViewTest_2.PageSize = 20;
                                bibleViewTest_2.TotalPage = 0;
                                bibleViewTest_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewTest_2.GetPhoneInfoUrl(bibleViewTest_2.CurrentPage, 5, pid_2)));
                                bibleViewTest_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleTest_2.DataContext = bibleViewTest_2;
                            }

                            break;
                        case 2:
                            BibleTab_2.SelectedIndex = BibleTab.SelectedIndex;
                            if (bibleViewSkill_2 == null)
                            {
                                bibleViewSkill_2 = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewSkill_2.Result = 0;
                                bibleViewSkill_2.CurrentPage = 1;
                                bibleViewSkill_2.AllowAdd = false;
                                bibleViewSkill_2.PageSize = 20;
                                bibleViewSkill_2.TotalPage = 0;
                                bibleViewSkill_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewSkill.GetPhoneInfoUrl(bibleViewSkill_2.CurrentPage, 1, pid_2)));
                                bibleViewSkill_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleSkill_2.DataContext = bibleViewSkill_2;
                            }
                            break;
                        case 3:
                            BibleTab_2.SelectedIndex = BibleTab.SelectedIndex;

                            if (bibleViewBug_2 == null)
                            {
                                bibleViewBug_2 = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewBug_2.Result = 0;
                                bibleViewBug_2.CurrentPage = 1;
                                bibleViewBug_2.AllowAdd = false;
                                bibleViewBug_2.PageSize = 20;
                                bibleViewBug_2.TotalPage = 0;
                                bibleViewBug_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBug_2.GetPhoneInfoUrl(bibleViewBug_2.CurrentPage, 3, pid_2)));
                                bibleViewBug_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleBug_2.DataContext = bibleViewBug_2;
                            }
                            break;
                        case 4:
                            BibleTab_2.SelectedIndex = BibleTab.SelectedIndex;
                            if (bibleViewBuyPhone_2 == null)
                            {
                                bibleViewBuyPhone_2 = new BibleView();
                                ProgBar.Visibility = Visibility.Visible;
                                bibleViewBuyPhone_2.Result = 0;
                                bibleViewBuyPhone_2.CurrentPage = 1;
                                bibleViewBuyPhone_2.AllowAdd = false;
                                bibleViewBuyPhone_2.PageSize = 20;
                                bibleViewBuyPhone_2.TotalPage = 0;
                                bibleViewBuyPhone_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBuyPhone_2.GetPhoneInfoUrl(bibleViewBuyPhone_2.CurrentPage, 4, pid_2)));
                                bibleViewBuyPhone_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                                BibleBuyphone_2.DataContext = bibleViewBuyPhone_2;
                            }
                            break;
                    }
                    break;
            }
        }
        private void Pictrue_Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender == null) return;
            Pivot pv = sender as Pivot;
            if (pv == null) return;
            switch (pv.SelectedIndex)
            {
                case 0:
                    textPicture1.Visibility = Visibility.Visible;
                    textPictureWatch1.Visibility = Visibility.Visible;
                    textPicture2.Visibility = Visibility.Collapsed;
                    textPictureWatch2.Visibility = Visibility.Collapsed;
                    if (delIndex1) break;
                    imageIndex = -1;
                    break;
                case 1:
                    textPicture2.Visibility = Visibility.Visible;
                    textPictureWatch2.Visibility = Visibility.Visible;
                    textPicture1.Visibility = Visibility.Collapsed;
                    textPictureWatch1.Visibility = Visibility.Collapsed;
                    if (delIndex2) break;
                    imageIndex = -1;
                    if (typePicture_2 == null)
                    {
                        typePicture_2 = new TypePicture();
                        ProgBar.Visibility = Visibility.Visible;
                        typePicture_2.ImageVis = false;
                        typePicture_2.CurrentPage = 1;
                        typePicture_2.AllowAdd = false;
                        typePicture_2.PageSize = 20;
                        typePicture_2.TotalPage = 0;
                        typePicture_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typePicture_2.GetPhoneInfoUrl(pid_2, typePicture_2.CurrentPage)));
                        typePicture_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                        PictruePivotItem2.DataContext = typePicture_2;
                    }
                    break;
            }
        }
        private void TabControl_Bible_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (BiblePivot != null && BiblePivot.SelectedIndex == 1 && delIndex2) return;
            if (BiblePivot != null && BiblePivot.SelectedIndex == 0 && delIndex1) return;
            if (sender == null) return;
            TabControl tabControl = sender as TabControl;
            if (tabControl == null) return;
            if (BiblePivot == null) return;
            currentBible = -1;
            switch (tabControl.SelectedIndex)
            {
                case 0:
                    //0 行情
                    if (BiblePivot.SelectedIndex == 1)
                    {
                        if (bibleViewMarket_2 == null)
                        {
                            bibleViewMarket_2 = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewMarket_2.Result = 0;
                            bibleViewMarket_2.CurrentPage = 1;
                            bibleViewMarket_2.AllowAdd = false;
                            bibleViewMarket_2.PageSize = 20;
                            bibleViewMarket_2.TotalPage = 0;
                            bibleViewMarket_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewMarket_2.GetPhoneInfoUrl(bibleViewMarket_2.CurrentPage, 0, pid_2)));
                            bibleViewMarket_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleMarket_2.DataContext = bibleViewMarket_2;
                        }
                        break;
                    }
                    break;
                case 1:
                    //5 评测
                    if (BiblePivot.SelectedIndex == 0)
                    {
                        if (bibleViewTest == null)
                        {
                            bibleViewTest = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewTest.Result = 0;
                            bibleViewTest.CurrentPage = 1;
                            bibleViewTest.AllowAdd = false;
                            bibleViewTest.PageSize = 20;
                            bibleViewTest.TotalPage = 0;
                            bibleViewTest.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewTest.GetPhoneInfoUrl(bibleViewTest.CurrentPage, 5, pid_1)));
                            bibleViewTest.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleTest.DataContext = bibleViewTest;
                        }
                        break;
                    }
                    else if (BiblePivot.SelectedIndex == 1)
                    {
                        if (bibleViewTest_2 == null)
                        {
                            bibleViewTest_2 = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewTest_2.Result = 0;
                            bibleViewTest_2.CurrentPage = 1;
                            bibleViewTest_2.AllowAdd = false;
                            bibleViewTest_2.PageSize = 20;
                            bibleViewTest_2.TotalPage = 0;
                            bibleViewTest_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewTest_2.GetPhoneInfoUrl(bibleViewTest_2.CurrentPage, 5, pid_2)));
                            bibleViewTest_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleTest_2.DataContext = bibleViewTest_2;
                        }
                    }
                    break;
                case 2:
                    //1 技巧
                    if (BiblePivot.SelectedIndex == 0)
                    {
                        if (bibleViewSkill == null)
                        {
                            bibleViewSkill = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewSkill.Result = 0;
                            bibleViewSkill.CurrentPage = 1;
                            bibleViewSkill.AllowAdd = false;
                            bibleViewSkill.PageSize = 20;
                            bibleViewSkill.TotalPage = 0;
                            bibleViewSkill.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewSkill.GetPhoneInfoUrl(bibleViewSkill.CurrentPage, 1, pid_1)));
                            bibleViewSkill.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleSkill.DataContext = bibleViewSkill;
                        }
                    }
                    else if (BiblePivot.SelectedIndex == 1)
                    {
                        if (bibleViewSkill_2 == null)
                        {
                            bibleViewSkill_2 = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewSkill_2.Result = 0;
                            bibleViewSkill_2.CurrentPage = 1;
                            bibleViewSkill_2.AllowAdd = false;
                            bibleViewSkill_2.PageSize = 20;
                            bibleViewSkill_2.TotalPage = 0;
                            bibleViewSkill_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewSkill_2.GetPhoneInfoUrl(bibleViewSkill_2.CurrentPage, 1, pid_2)));
                            bibleViewSkill_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleSkill_2.DataContext = bibleViewSkill_2;
                        }
                    }

                    break;
                case 3:
                    //3 BUG
                    if (BiblePivot.SelectedIndex == 0)
                    {
                        if (bibleViewBug == null)
                        {
                            bibleViewBug = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewBug.Result = 0;
                            bibleViewBug.CurrentPage = 1;
                            bibleViewBug.AllowAdd = false;
                            bibleViewBug.PageSize = 20;
                            bibleViewBug.TotalPage = 0;
                            bibleViewBug.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBug.GetPhoneInfoUrl(bibleViewBug.CurrentPage, 3, pid_1)));
                            bibleViewBug.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleBug.DataContext = bibleViewBug;
                        }
                    }
                    else if (BiblePivot.SelectedIndex == 1)
                    {
                        if (bibleViewBug_2 == null)
                        {
                            bibleViewBug_2 = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewBug_2.Result = 0;
                            bibleViewBug_2.CurrentPage = 1;
                            bibleViewBug_2.AllowAdd = false;
                            bibleViewBug_2.PageSize = 20;
                            bibleViewBug_2.TotalPage = 0;
                            bibleViewBug_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBug_2.GetPhoneInfoUrl(bibleViewBug_2.CurrentPage, 3, pid_2)));
                            bibleViewBug_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleBug_2.DataContext = bibleViewBug_2;
                        }
                    }
                    break;

                case 4:
                    if (BiblePivot.SelectedIndex == 0)
                    {
                        if (bibleViewBuyPhone == null)
                        {
                            bibleViewBuyPhone = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewBuyPhone.Result = 0;
                            bibleViewBuyPhone.CurrentPage = 1;
                            bibleViewBuyPhone.AllowAdd = false;
                            bibleViewBuyPhone.PageSize = 20;
                            bibleViewBuyPhone.TotalPage = 0;
                            //
                            bibleViewBuyPhone.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBuyPhone.GetPhoneInfoUrl(bibleViewBuyPhone.CurrentPage, 4, pid_1)));
                            bibleViewBuyPhone.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleBuyphone.DataContext = bibleViewBuyPhone;
                        }
                    }
                    else if (BiblePivot.SelectedIndex == 1)
                    {
                        if (bibleViewBuyPhone_2 == null)
                        {
                            bibleViewBuyPhone_2 = new BibleView();
                            ProgBar.Visibility = Visibility.Visible;
                            bibleViewBuyPhone_2.Result = 0;
                            bibleViewBuyPhone_2.CurrentPage = 1;
                            bibleViewBuyPhone_2.AllowAdd = false;
                            bibleViewBuyPhone_2.PageSize = 20;
                            bibleViewBuyPhone_2.TotalPage = 0;
                            //
                            bibleViewBuyPhone_2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(bibleViewBuyPhone_2.GetPhoneInfoUrl(bibleViewBuyPhone_2.CurrentPage, 4, pid_2)));
                            bibleViewBuyPhone_2.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(type_PropertyChanged);
                            BibleBuyphone_2.DataContext = bibleViewBuyPhone_2;
                        }
                    }
                    //4 购机
                    break;

            }
        }
        private void ListBox_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender == null) return;
            ListBox lb = sender as ListBox;
            if (lb == null) return;
            PhoneInfoCenterItem itemInList = lb.SelectedItem as PhoneInfoCenterItem;
            if (itemInList == null) return;
            string objective = "/Page/ContentAndReply.xaml";
            if (itemInList.Topicid == null)
            {
                MessageBox.Show("该帖子ID有错误，请刷新后重试！");
                return;
            }
            objective += "?topicid=" + itemInList.Topicid;
            objective += "&readcount=" + itemInList.Readcount;
            objective += "&replycount=" + itemInList.Replycount;
            objective += "&title=" + itemInList.Title;
            string IsBible = "0";
            if (BibleTab.SelectedIndex != 0) { IsBible = "1"; }
            objective += "&IsBible=" + IsBible;
            NavigationService.Navigate(new Uri(objective, UriKind.Relative));
        }
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (isShowPK1)
            {
                sto1_hide.Begin();
                e.Cancel = true;
            }
            if (isShowPK2)
            {
                sto2_hide.Begin();
                e.Cancel = true;
            }

            //这里可以执行弹出对话框操作
            if (PopFull.IsOpen == true)
            {
                SystemTray.IsVisible = true;
                ProgBarPop.Visibility = Visibility.Collapsed;
                Advant.IsEnabled = true;
                Defect.IsEnabled = true;
                Conmmit.IsEnabled = true;
                PopFull.IsOpen = false;
                e.Cancel = true;
            }
            if (ImagePoP.IsOpen == true)
            {
                SystemTray.IsVisible = true;
                ImagePoP.IsOpen = false;
                image.Source = null;
                imageIndex = -1;
                e.Cancel = true;
                ApplicationBar = null;
            }
            if (PopConmment.IsOpen == true)
            {
                e.Cancel = true;
                SystemTray.IsVisible = true;
                qualityCheckBox.IsEnabled = true;
                breedCheckBox.IsEnabled = true;
                priceCheckBox.IsEnabled = true;
                effectCheckBox.IsEnabled = true;
                faceCheckBox.IsEnabled = true;
                otherCheckBox.IsEnabled = true;
                qualityCheckBox.IsChecked = false;
                breedCheckBox.IsChecked = false;
                priceCheckBox.IsChecked = false;
                effectCheckBox.IsChecked = false;
                faceCheckBox.IsChecked = false;
                otherCheckBox.IsChecked = false;
                VoteButtonOk.IsEnabled = true;
                VoteButtonCancel.IsEnabled = true;
                PopConmment.IsOpen = false;
            }

        }
        private void Conmit_Click(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            string defect = Advant.Text;
            string advant = Defect.Text;
            if (defect.Length < 6 || defect.Length > 120)
            {
                MessageBox.Show("缺点必须为6至120个字！");
                return;
            }
            if (advant.Length < 6 || advant.Length > 120)
            {
                MessageBox.Show("优点必须为6至120个字！");
                return;
            }
            //等事件完成了再唤出工具条
            ProgBarPop.Visibility = Visibility.Visible;
            Advant.IsEnabled = false;
            Defect.IsEnabled = false;
            ((Button)sender).IsEnabled = false;
            int startNumber = StartControl.Marked;
            ReplyResult rpResut = new ReplyResult();

            if (commentPivot.SelectedIndex == 0)
                rpResut.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(rpResut.GetPhoneInfoUrl(pid_1, startNumber, advant, defect)));
            else if (commentPivot.SelectedIndex == 1)
                rpResut.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(rpResut.GetPhoneInfoUrl(pid_2, startNumber, advant, defect)));
            rpResut.PropertyChanged += new PropertyChangedEventHandler(type_PropertyChanged);
        }
        private void PhonePkCommentOk(object sender, RoutedEventArgs e)
        {
            if (addVoteNumer == 1)
            {
                ProgBar.Visibility = Visibility.Visible;
                qualityCheckBox.IsEnabled = false;
                breedCheckBox.IsEnabled = false;
                priceCheckBox.IsEnabled = false;
                effectCheckBox.IsEnabled = false;
                faceCheckBox.IsEnabled = false;
                otherCheckBox.IsEnabled = false;
                ReplyResult VoteResult1 = new ReplyResult();
                VoteResult1.className = "VoteResult1";
                VoteResult1.PropertyChanged += new PropertyChangedEventHandler(Vote_Result_PropertyChanged);
                VoteButtonOk.IsEnabled = true;
                VoteButtonCancel.IsEnabled = true;
                VoteResult1.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(VoteResult1.GetPhoneInfoUrl(pid_1,
                                     qualityCheckBox.IsChecked.ToString(),
                                    breedCheckBox.IsChecked.ToString(),
                                    priceCheckBox.IsChecked.ToString(),
                                     effectCheckBox.IsChecked.ToString(),
                                    faceCheckBox.IsChecked.ToString(),
                                    otherCheckBox.IsChecked.ToString())));
            }
            else if (addVoteNumer == 2)
            {
                ProgBar.Visibility = Visibility.Visible;
                qualityCheckBox.IsEnabled = false;
                breedCheckBox.IsEnabled = false;
                priceCheckBox.IsEnabled = false;
                effectCheckBox.IsEnabled = false;
                faceCheckBox.IsEnabled = false;
                otherCheckBox.IsEnabled = false;
                VoteButtonOk.IsEnabled = false;
                VoteButtonCancel.IsEnabled = false;
                ReplyResult VoteResult2 = new ReplyResult();
                VoteResult2.PropertyChanged += new PropertyChangedEventHandler(Vote_Result_PropertyChanged);
                VoteResult2.className = "VoteResult2";
                VoteResult2.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(VoteResult2.GetPhoneInfoUrl(pid_2,
                                   qualityCheckBox.IsChecked.ToString(),
                                   breedCheckBox.IsChecked.ToString(),
                                   priceCheckBox.IsChecked.ToString(),
                                  effectCheckBox.IsChecked.ToString(),
                                  faceCheckBox.IsChecked.ToString(),
                                   otherCheckBox.IsChecked.ToString())));

            }
        }
        private void PhonePkCommentCancl(object sender, RoutedEventArgs e)
        {
            SystemTray.IsVisible = true;
            qualityCheckBox.IsEnabled = true;
            breedCheckBox.IsEnabled = true;
            priceCheckBox.IsEnabled = true;
            effectCheckBox.IsEnabled = true;
            faceCheckBox.IsEnabled = true;
            otherCheckBox.IsEnabled = true;
            VoteButtonOk.IsEnabled = true;
            VoteButtonCancel.IsEnabled = true;
            PopConmment.IsOpen = false;
        }
        private void Add_Vote1(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            addVoteNumer = 1;
            SystemTray.IsVisible = false;
            PopConmment.Visibility = Visibility.Visible;
            PopConmment.IsOpen = true;
        }
        private void Add_Vote2(object sender, RoutedEventArgs e)
        {
            if (sender == null) return;
            addVoteNumer = 2;
            ReplyResult VoteResult2 = new ReplyResult();
            VoteResult2.className = "VoteResult2";
            SystemTray.IsVisible = false;
            PopConmment.Visibility = Visibility.Visible;
            PopConmment.IsOpen = true;
        }
        void Vote_Result_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (sender == null) return;
            ReplyResult rr = sender as ReplyResult;
            if (rr != null)
            {
                if (e.PropertyName == "Result")
                {
                    if (rr.Result == 2)
                    {//成功
                        ProgBar.Visibility = Visibility.Collapsed;
                        SystemTray.IsVisible = false;
                        qualityCheckBox.IsEnabled = true;
                        breedCheckBox.IsEnabled = true;
                        priceCheckBox.IsEnabled = true;
                        effectCheckBox.IsEnabled = true;
                        faceCheckBox.IsEnabled = true;
                        otherCheckBox.IsEnabled = true;
                        qualityCheckBox.IsChecked = false;
                        breedCheckBox.IsChecked = false;
                        priceCheckBox.IsChecked = false;
                        effectCheckBox.IsChecked = false;
                        faceCheckBox.IsChecked = false;
                        otherCheckBox.IsChecked = false;
                        VoteButtonOk.IsEnabled = true;
                        VoteButtonCancel.IsEnabled = true;
                        PopConmment.IsOpen = false;
                        new ToastPrompt() { Message = "投票成功！" }.Show();
                    }
                    else
                    {//失败

                        ProgBarPop.Visibility = Visibility.Collapsed;
                        SystemTray.IsVisible = false;
                        qualityCheckBox.IsEnabled = true;
                        breedCheckBox.IsEnabled = true;
                        priceCheckBox.IsEnabled = true;
                        effectCheckBox.IsEnabled = true;
                        faceCheckBox.IsEnabled = true;
                        otherCheckBox.IsEnabled = true;
                        qualityCheckBox.IsChecked = false;
                        breedCheckBox.IsChecked = false;
                        priceCheckBox.IsChecked = false;
                        effectCheckBox.IsChecked = false;
                        faceCheckBox.IsChecked = false;
                        otherCheckBox.IsChecked = false;
                        VoteButtonOk.IsEnabled = true;
                        VoteButtonCancel.IsEnabled = true;
                        PopConmment.IsOpen = false;
                        MessageBox.Show("提投票论失败，点确定退出，点取消继续重试", "提示", MessageBoxButton.OK | MessageBoxButton.OKCancel);
                    }
                }
            }
        }
        private void ListBoxImage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender == null) return;
            ListBox list = sender as ListBox;
            if (list == null) return;
            TypePictureItem item = list.SelectedItem as TypePictureItem;
            imageIndex = list.SelectedIndex;
            if (item == null) return;
            SystemTray.IsVisible = false; ApplicationBar = null;
            ImagePoP.IsOpen = true;

            ApplicationBar = (ApplicationBar)this.Resources["AppBar"];
            image.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(item.Acturl));
            image.SetValue(LowProfileImageLoader.UriSourceProperty, new Uri(item.Acturl));
            ListBox lst = sender as ListBox;
        }
        private void Popup_Flick(object sender, FlickGestureEventArgs e)
        {
            if (sender == null || typePicture == null) return;
            if (e.HorizontalVelocity < 0)
            {
                if (imageIndex < typePicture.TypePictureItems.Count - 1)
                {
                    imageIndex += 1;
                    image.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typePicture.TypePictureItems[imageIndex].Acturl));
                }
            }
            else if (e.HorizontalVelocity > 0)
            {//向右滑动
                if (imageIndex > 0)
                {//向左滑动
                    imageIndex -= 1;
                    image.SetValue(LowProfileXmlLoader.UriSourceProperty, new Uri(typePicture.TypePictureItems[imageIndex].Acturl));
                }
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn1 = sender as Button;
            if (btn1.Tag.ToString() != "/icon/selectCenter/pkbtn.png")
            {

                foreach (ProgressBar fe in GetChildObjects<ProgressBar>(LayoutRoot, "t1_value"))
                    fe.Value = 0;
                foreach (PhonePkDetailItem item in typeParameter.TypeParameterItems)
                    item.Content = null;
                foreach (TextBlock fe in GetChildObjects<TextBlock>(LayoutRoot, "t1"))
                    fe.Text = "";
                Ex1();
            }
            else
            {
                if (delIndex2)
                {
                    NavigationService.Navigate(new Uri("/Page/MobileProduct.xaml?isnull=1&ispk=1", UriKind.Relative));
                }
                else
                {
                    if (tabswitch.SelectedIndex != 0) tabswitch.ChangeSelected(0);
                    sto1.Begin();
                }
            }
            return;
        }

        void Ex1()
        {
            TextType1.Text = "选择机型";
            TextType1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            typePhone1.Source = null;

            textPictureName1.Text = "选择机型";
            textPictureName1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImagePictureName1.Source = null;

            textTypeName1.Text = "选择机型";
            textTypeName1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageTypeName1.Source = null;

            textCommentName1.Text = "选择机型";
            textCommentName1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageCommentName1.Source = null;

            textPictureName1.Text = "选择机型";
            textPictureName1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImagePictureName1.Source = null;

            textBibleName1.Text = "选择机型";
            textBibleName1.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageBibleName1.Source = null;

            nameBtn1.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn1_1.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn2_1.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn3_1.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn4_1.Tag = "/icon/selectCenter/pkbtn.png";

            PivotItem it1 = PricePivot.Items[1] as PivotItem;
            it1.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it1.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it1.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it2 = commentPivot.Items[1] as PivotItem;
            it2.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it2.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it2.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it3 = picturePivot.Items[1] as PivotItem;
            it3.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it3.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it3.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it4 = BiblePivot.Items[1] as PivotItem;
            it4.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it4.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it4.ManipulationStarted += KLPivotItem_ManipulationStarted;
            if (tabswitch.SelectedIndex != 0) tabswitch.ChangeSelected(0);
            delIndex1 = true;
            ClearData(1);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Button btn2 = sender as Button;
            if (btn2.Tag.ToString() != "/icon/selectCenter/pkbtn.png")
            {
                foreach (TextBlock fe in GetChildObjects<TextBlock>(LayoutRoot, "t2"))
                    fe.Text = "";
                foreach (ProgressBar fe in GetChildObjects<ProgressBar>(LayoutRoot, "t2_value"))
                    fe.Value = 0;
                foreach (PhonePkDetailItem item in typeParameter.TypeParameterItems)
                    item.Content_2 = null;
                Ex2();
            }
            else
            {
                if (delIndex1)
                {
                    NavigationService.Navigate(new Uri("/Page/MobileProduct.xaml?ispk=1&isnull=1", UriKind.Relative));
                }
                else
                {
                    if (tabswitch.SelectedIndex != 0) tabswitch.ChangeSelected(0);
                    sto2.Begin();
                }
            }
        }

        void Ex2()
        {
            TextType2.Text = "选择机型";
            TextType2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            typePhone2.Source = null;

            textPictureName2.Text = "选择机型";
            textPictureName2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImagePictureName2.Source = null;

            textTypeName2.Text = "选择机型";
            textTypeName2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageTypeName2.Source = null;

            textCommentName2.Text = "选择机型";
            textCommentName2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageCommentName2.Source = null;

            textPictureName2.Text = "选择机型";
            textPictureName2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImagePictureName2.Source = null;

            textBibleName2.Text = "选择机型";
            textBibleName2.Foreground = new SolidColorBrush(Common.HtmlToColor("#FF7A9AB7"));
            ImageBibleName2.Source = null;

            nameBtn2.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn1_2.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn2_2.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn3_2.Tag = "/icon/selectCenter/pkbtn.png";
            nameBtn4_2.Tag = "/icon/selectCenter/pkbtn.png";

            PivotItem it1 = PricePivot.Items[0] as PivotItem;
            it1.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it1.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it1.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it2 = commentPivot.Items[0] as PivotItem;
            it2.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it2.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it2.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it3 = picturePivot.Items[0] as PivotItem;
            it3.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it3.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it3.ManipulationStarted += KLPivotItem_ManipulationStarted;

            PivotItem it4 = BiblePivot.Items[0] as PivotItem;
            it4.ManipulationCompleted += KLPivotItem_ManipulationCompleted;
            it4.ManipulationDelta += KLPivotItem_ManipulationDelta;
            it4.ManipulationStarted += KLPivotItem_ManipulationStarted;
            if (tabswitch.SelectedIndex != 0) tabswitch.ChangeSelected(0);
            delIndex2 = true;
            ClearData(2);
        }

        void ClearData(int i)
        {
            if (i == 1)
            {
                if (BibleBuyphone != null) BibleBuyphone.DataContext = null;
                if (BibleBug != null) BibleBug.DataContext = null;
                if (BibleSkill != null) BibleSkill.DataContext = null;
                if (BibleTest != null) BibleTest.DataContext = null;
                if (BibleMarket != null) BibleMarket.DataContext = null;
                if (TypePriceList1 != null) TypePriceList1.DataContext = null;
                if (commetPivotItem_1 != null) commetPivotItem_1.DataContext = null;
                if (TypePriceList1 != null) TypePriceList1.DataContext = null;
                if (PictruePivotItem1 != null) PictruePivotItem1.DataContext = null;
                Textsc1.Text = ""; sc1.Value = 0;
                Textsc2.Text = ""; sc2.Value = 0;
                Textsc3.Text = ""; sc3.Value = 0;
                Textsc4.Text = ""; sc4.Value = 0;
                Textsc5.Text = ""; sc5.Value = 0;
                scoreText.Text = "0";
                ScoreStart.Marked = 0;
            }
            else if (i == 2)
            {
                if (BibleBuyphone_2 != null) BibleBuyphone_2.DataContext = null;
                if (BibleBug_2 != null) BibleBug_2.DataContext = null;
                if (BibleSkill_2 != null) BibleSkill_2.DataContext = null;
                if (BibleTest_2 != null) BibleTest_2.DataContext = null;
                if (BibleMarket_2 != null) BibleMarket_2.DataContext = null;
                if (TypePriceList2 != null) TypePriceList2.DataContext = null;
                if (commetPivotItem_2 != null) commetPivotItem_2.DataContext = null;
                if (TypePriceList2 != null) TypePriceList2.DataContext = null;
                if (PictruePivotItem2 != null) PictruePivotItem2.DataContext = null;
                Textsc1_2.Text = ""; sc1_2.Value = 0;
                Textsc2_2.Text = ""; sc2_2.Value = 0;
                Textsc3_2.Text = ""; sc3_2.Value = 0;
                Textsc4_2.Text = ""; sc4_2.Value = 0;
                Textsc5_2.Text = ""; sc5_2.Value = 0;
                scoreText_2.Text = "0";
                ScoreStart_2.Marked = 0;
            }
        }

        private void KLPivotItem_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            e.Handled = true;
        }

        private void KLPivotItem_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            e.Handled = true;
        }

        private void KLPivotItem_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            e.Handled = true;
        }

        public List<T> GetChildObjects<T>(DependencyObject obj, string tag) where T : FrameworkElement
        {
            DependencyObject child = null;
            List<T> childList = new List<T>();

            for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
            {
                child = VisualTreeHelper.GetChild(obj, i);

                if (child is T && ((T)child).Tag != null && ((T)child).Tag.ToString() == tag)
                {
                    childList.Add((T)child);
                }
                childList.AddRange(GetChildObjects<T>(child, tag));
            }
            return childList;
        }

        public List<T> GetChildObjects2<T>(DependencyObject obj, string name) where T : FrameworkElement
        {
            DependencyObject child = null;
            List<T> childList = new List<T>();
            for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
            {
                child = VisualTreeHelper.GetChild(obj, i);
                if (child is T)
                    childList.Add((T)child);
                childList.AddRange(GetChildObjects2<T>(child, ""));
            }
            return childList;
        }

        private void BtnPK_Jia(object sender, RoutedEventArgs e)
        {
            int price = 0;
            if (jia2 == null || int.TryParse(jia2, out  price))
            {
                string stt_price;
                string page = "/Page/SearchResult.xaml";
                if (price == 0)
                    stt_price = "";
                else if (price <= 1000)
                    stt_price = "1";
                else if (price <= 2000)
                    stt_price = "2";
                else if (price <= 3000)
                    stt_price = "3";
                else if (price > 3000)
                    stt_price = "4";
                else
                    stt_price = "";
                page += "?price_1=" + jia2;
                page += "&pid_1=" + pid_2;
                page += "&price=" + stt_price;
                page += "&ppname_1=" + ppname2;
                page += "&picurl_1=" + Imageurl2;
                page += "&phonename_1=" + phonename2;
                NavigationService.Navigate(new Uri(page, UriKind.Relative));
            }
        }

        private void BtnPK_Pin(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname2;
            page += "&pid_1=" + pid_2;
            page += "&ppid_1=" + ppid2;
            page += "&price_1=" + jia2;
            page += "&picurl_1=" + Imageurl2;
            page += "&phonename_1=" + phonename2;
            sto1_hide.Begin();
            sto1_hide.Completed += (SoftDetail_Screen, __) =>
                { NavigationService.Navigate(new Uri(page, UriKind.Relative)); };
        }

        private void BtnPK_Fen(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname2;
            page += "&pid_1=" + pid_2;
            page += "&price_1=" + jia2;
            page += "&picurl_1=" + Imageurl2;
            page += "&phonename_1=" + phonename2;
            string xs = "";
            foreach (PhonePkDetailItem i in typeParameter.TypeParameterItems)
            {
                if (i.Title == "主屏分辨率")
                    xs = i.Content_2.Replace("像素", "").Replace("X", "*").Replace("x", "*");
            }
            int tag = 0;
            if (xs == "240*320" || xs == "320*240") tag = 1;
            else if (xs == "320*480" || xs == "480*320") tag = 2;
            else if (xs == "360*640" || xs == "640*360") tag = 3;
            else if (xs == "480*800" || xs == "800*480") tag = 4;
            else if (xs == "480*854" || xs == "854*480") tag = 5;
            else if (xs == "540*960" || xs == "960*540") tag = 6;
            else if (xs == "640*960" || xs == "960*640") tag = 7;
            else if (xs == "800*1280" || xs == "1280*800") tag = 8;
            page += "&distingwish=" + (tag == 0 ? "" : tag.ToString());
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Xi(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname2;
            page += "&pid_1=" + pid_2;
            page += "&price_1=" + jia2;
            page += "&picurl_1=" + Imageurl2;
            page += "&phonename_1=" + phonename2;
            string xs = "";
            foreach (PhonePkDetailItem i in typeParameter.TypeParameterItems)
            {
                if (i.Title == "操作系统")
                    xs = i.Content_2.ToLower();
            }
            int tag = 0;
            if (xs.IndexOf("symbian") > -1) tag = 1;
            else if (xs.IndexOf("android") > -1) tag = 2;
            else if (xs.IndexOf("windows phone") > -1) tag = 8;
            else if (xs.IndexOf("Linux") > -1) tag = 4;
            else if (xs.IndexOf("MTK") > -1) tag = 5;
            else if (xs.IndexOf("其它") > -1) tag = 6;
            else if (xs.IndexOf("Apple") > -1) tag = 7;
            else if (xs.IndexOf("windows") > -1) tag = 3;
            page += "&system=" + (tag == 0 ? "" : tag.ToString());
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Qita(object sender, RoutedEventArgs e)
        {
            string page = "/Page/MobileProduct.xaml";
            page += "?ispk=1&ppname_1=" + ppname2;
            page += "&pid_1=" + pid_2;
            page += "&ppid_1=" + ppid2;
            page += "&price_1=" + jia2;
            page += "&picurl_1=" + Imageurl2;
            page += "&phonename_1=" + phonename2;
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Pin2(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname1;
            page += "&pid_1=" + pid_1;
            page += "&ppid_1=" + ppid1;
            page += "&price_1=" + jia1;
            page += "&picurl_1=" + Imageurl1;
            page += "&phonename_1=" + phonename1;
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Jia2(object sender, RoutedEventArgs e)
        {
            int price = 0;
            if (jia1 == null || int.TryParse(jia1, out  price))
            {
                string stt_price;
                string page = "/Page/SearchResult.xaml";
                if (price == 0)
                    stt_price = "";
                else if (price <= 1000)
                    stt_price = "1";
                else if (price <= 2000)
                    stt_price = "2";
                else if (price <= 3000)
                    stt_price = "3";
                else if (price > 3000)
                    stt_price = "4";
                else
                    stt_price = "";
                page += "?price_1=" + jia1;
                page += "&pid_1=" + pid_1;
                page += "&price=" + stt_price;
                page += "&ppname_1=" + ppname1;
                page += "&picurl_1=" + Imageurl1;
                page += "&phonename_1=" + phonename1;
                NavigationService.Navigate(new Uri(page, UriKind.Relative));
            }
        }

        private void BtnPK_Fen2(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname1;
            page += "&pid_1=" + pid_1;
            page += "&price_1=" + jia1;
            page += "&picurl_1=" + Imageurl1;
            page += "&phonename_1=" + phonename1;
            string xs = "";
            foreach (PhonePkDetailItem i in typeParameter.TypeParameterItems)
            {
                if (i.Title == "主屏分辨率")
                    xs = i.Content.Replace("像素", "").Replace("X", "*").Replace("x", "*");
            }
            int tag = 0;
            if (xs == "240*320" || xs == "320*240") tag = 1;
            else if (xs == "320*480" || xs == "480*320") tag = 2;
            else if (xs == "360*640" || xs == "640*360") tag = 3;
            else if (xs == "480*800" || xs == "800*480") tag = 4;
            else if (xs == "480*854" || xs == "854*480") tag = 5;
            else if (xs == "540*960" || xs == "960*540") tag = 6;
            else if (xs == "640*960" || xs == "960*640") tag = 7;
            else if (xs == "800*1280" || xs == "1280*800") tag = 8;
            page += "&distingwish=" + (tag == 0 ? "" : tag.ToString());
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Xi2(object sender, RoutedEventArgs e)
        {
            string page = "/Page/SearchResult.xaml";
            page += "?ppname_1=" + ppname2;
            page += "&pid_1=" + pid_2;
            page += "&price_1=" + jia2;
            page += "&picurl_1=" + Imageurl2;
            page += "&phonename_1=" + phonename2;
            string xs = "";
            foreach (PhonePkDetailItem i in typeParameter.TypeParameterItems)
            {
                if (i.Title == "操作系统")
                    xs = i.Content;
            }
            int tag = 0;
            if (xs.IndexOf("symbian") > -1) tag = 1;
            else if (xs.IndexOf("android") > -1) tag = 2;
            else if (xs.IndexOf("windows phone") > -1) tag = 8;
            else if (xs.IndexOf("Linux") > -1) tag = 4;
            else if (xs.IndexOf("MTK") > -1) tag = 5;
            else if (xs.IndexOf("其它") > -1) tag = 6;
            else if (xs.IndexOf("Apple") > -1) tag = 7;
            else if (xs.IndexOf("windows") > -1) tag = 3;
            page += "&system=" + (tag == 0 ? "" : tag.ToString());
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

        private void BtnPK_Qita2(object sender, RoutedEventArgs e)
        {
            string page = "/Page/MobileProduct.xaml";
            page += "?ispk=1&ppname_1=" + ppname1;
            page += "&pid_1=" + pid_1;
            page += "&ppid_1=" + ppid1;
            page += "&price_1=" + jia1;
            page += "&picurl_1=" + Imageurl1;
            page += "&phonename_1=" + phonename1;
            NavigationService.Navigate(new Uri(page, UriKind.Relative));
        }

    }
}